package com.example.demo.utils;

import org.springframework.stereotype.Component;
import org.apache.commons.codec.digest.DigestUtils;


/**
 * @author 何景航
 * @date 2025/5/30 13:53
 */
@Component
public class MD5Util {
    public static String md5(String src) {
        return DigestUtils.md5Hex(src);
    }
    private static final String salt = "1a2b3c4d";
    //第一次加密
    public static String inputPassToFormPass(String inputPass) {
        String str =  salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        return md5(str);
    }
    //第二次加密
    public static String formPassToDBPass(String formPass, String salt) {
        String str =  salt.charAt(0) + salt.charAt(2) + formPass + salt.charAt(5) + salt.charAt(4);
        return md5(str);
    }
    public static String inputPassToDBPass(String inputPass, String salt) {
        String formPass = inputPassToFormPass(inputPass);
        String dbPass = formPassToDBPass(formPass, salt);
        return dbPass;
    }
    public static void main(String[] args) {
//        ce21b747de5af71ab5c2e20ff0a60eea
        System.out.println(inputPassToFormPass("123456"));
//        0687f9701bca74827fcefcd7e743d179
        System.out.println(formPassToDBPass("ce21b747de5af71ab5c2e20ff0a60eea","1a2b3c4d"));
    }
}
